//
//  DayTicketViewModel.m
//  didacar
//
//  Created by 度周末网络-王腾 on 15/12/11.
//  Copyright © 2015年 dzmmac. All rights reserved.
//

#import "DayTicketViewModel.h"
#import "UserInfoManager.h"
#import "UserInfoModel.h"
#import "DayTicketModel.h"
#import "ResponseDayModel.h"
@implementation DayTicketViewModel

-(id)init{
    self.dayTicketPrices    = [[NSMutableArray alloc ] init];
    self.dayTicketPricesOrigin = [[NSMutableArray alloc ] init];
    return [super init];
}

/**
 *  加载日票的价格日历
 *
 *  @param resultBlock
 */
-(void)loadDayTicketData:(DealDataResultBlock)resultBlock{
    NSMutableDictionary *postDic = [[NSMutableDictionary alloc ] init];
    [postDic setObj:USERINFOManager.getUserInfo.MemberId forKey:@"MemberId"];
    [postDic setObj:self.LineId forKey:@"LineId"];
    [postDic setObj:@(self.BCID) forKey:@"BCID"];
    [postDic setObj:@(self.StartStationId) forKey:@"StartStationId"];
    [postDic setObj:@(self.EndStationId) forKey:@"EndStationId"];
    
    
    WEAKSELF
    [[BaseHttpRequest sharedInstance] sendRequestToPost:DayTicketPrice withData:postDic alertMessage:@"" success:^(NSDictionary *dicData) {
        
        
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            // 上下车站点信息。不包含拐角
            [weakSelf.dayTicketPrices removeAllObjects];
            
            NSDictionary *daysdic = [dicData objectForKey:@"workPriceList"];
            for (NSArray *array in daysdic.allValues) {
                for (NSInteger i = 0; i < array.count; i ++) {
                    DayTicketModel *dayticketModel = [[DayTicketModel alloc ] initWithDictionary:[array objectAtIndex:i]];
                    [weakSelf.dayTicketPricesOrigin addObject:dayticketModel];
                    ResponseDayModel *model = [[ResponseDayModel alloc] init];
                    model.time = dayticketModel.WorkDate;
                    
                    if (weakSelf.IsSale == 1) {
                           model.price = [dayticketModel.SalePrice stringValue];
                    }else{
                           model.price = [dayticketModel.TicketPrice stringValue];
                    }
                    
                    model.ticketStyle = dayticketModel.Type;
                    model.SalePrice = dayticketModel.SalePrice;
                    model.BCID = dayticketModel.BCID;
                    [weakSelf.dayTicketPrices addObject:model];
                }
            }
            
            dispatch_async(dispatch_get_main_queue(), ^{
                 resultBlock(1,nil,nil);
            });
        });
        
    } error:^(NSString *errorMsg) {
        resultBlock(0,nil,errorMsg);
    }];
}

@end
